<div id="result">
    <div id="titlebar-popup" class="titlebar">
        <div class="bar-control">   
            <?php
            echo CHtml::button(t('BTN_APPROVE', 'article'), // the link for open the dialog  
                    array(
                'onclick' => "{approve(); $('#dialogClassroom').dialog('open');}",
                'class' => "btnStatus",
                'style' => "font: bold 11px sans-serif;margin-left:10px"));
            echo CHtml::button(t('BTN_REJECT', 'article'), // the link for open the dialog  
                    array(
                'onclick' => "{reject(); $('#dialogClassroom').dialog('open');}",
                'class' => "btnStatus",
                'style' => "font: bold 11px sans-serif;margin-left:10px"));
            echo CHtml::button(t('BTN_DELETE'), // the link for open the dialog  
                    array(
                'onclick' => "{deleteComment(); $('#dialogClassroom').dialog('open');}",
                'class' => "btnStatus",
                'style' => "font: bold 11px sans-serif;margin-left:10px"));
            ?> 
        </div>
        <h1><?php echo CHtml::encode($model->commentRelation->title);?></h1>
    </div>

    <div class="main-content">
        <!-- search-form -->
        <div class="search-form" >
            <?php
            $this->renderPartial('_search_comment', array(
                'model' => $model,
            ));
            ?>
        </div>

        <?php
	
        $this->widget('GridView', array(
            'id' => 'DataGridPopup' /*. uniqid()*/, 
            'dataProvider' => $model->searchComment(),
            'afterAjaxUpdate' => 'js:function(id, data) {
                var obj = jQuery.parseJSON(data);
                $("#update-dialog").children().html(obj.content);
                return false;
            }',
            'ajaxUpdate' => 'DataGridPopup', 
            'columns' => array(
                array(
                    'header' => '#',
                    'class' => 'CCheckBoxColumn',
                    'selectableRows' => '50',
                    'id' => 'chkPopupId',
                ),
                array(
                    'header' => t('LBL_COMMENT_TEXT', 'article'),
                    'name' => 'comment_text',
                    'htmlOptions' => array('align' => 'left'),
                    'value' => 'CHtml::encode($data->comment_text)',
                ),
                array(
                    'header' => t('LBL_USERNAME', 'article'),
                    'name' => 'created_by',
                    'htmlOptions' => array('align' => 'center', 'width' => '150px'),
                    'value' => 'CHtml::encode($data->created_by)',
                ),
                array(
                    'header' => t('LBL_CREATE_DATE', 'article'),
                    'name' => 'create_date',
                    'htmlOptions' => array('align' => 'center', 'style' => 'width:150px;'),
                     'sortable' => TRUE,
                ),
                array(
                    'name' => 'status',
                    'htmlOptions' => array('align' => 'center', 'width' => '80px;'),
                    'value' => 'LGHelpers::getNameCommentStatus($data->status)',
                ),
            ),
        ));
        ?>
    </div>
</div>
<script type="text/javascript"> 
    $("button.ok").live('click',function(e){
        var DataGridPopup=$("#result").children().eq(1).children().eq(1).attr("id");
        if(!e.isDefaultPrevented()){
            <?php
            $urlApprove = url("article/approve");
            $urlReject = url("article/reject");
            $urlDeleteComment = url("article/deleteComment");
            ?>
            e.preventDefault();
            if ($("#hfStatus").val()=="Approve"){
                $.ajax({
                    url: '<?php echo $urlApprove ?>',//+'?id='+$("#hfId").val(),
                    type:"POST",  
                    data: {id:$("#hfId").val()},
                    success:function(data)
                    {
                        $('#dialogClassroom').dialog('close'); 
                        $.fn.yiiGridView.update(DataGridPopup);

                    }    
                });
            }else if ($("#hfStatus").val()=="Reject"){
                $.ajax({
                    url: '<?php echo $urlReject ?>',
                    type:"post",  
                    data: {id:$("#hfId").val()}, 
                    success:function(data)
                    {
                  
                        $('#dialogClassroom').dialog('close');    
                        $.fn.yiiGridView.update(DataGridPopup);
                    }    
                });
            }else if ($("#hfStatus").val()=="DeleteComment"){
                $.ajax({
                    url: '<?php echo $urlDeleteComment ?>',
                    type:"post",  
                    data: {id:$("#hfId").val()},
                    success:function(data)
                    {
                        $('#dialogClassroom').dialog('close');    
                        $.fn.yiiGridView.update(DataGridPopup);
                    }    
                });
            }
        }    
    });
    $(".cancel").live('click',function(){    
        $('#dialogClassroom').dialog('close');
    });
    // here is the magic 
    function approve(){
        var DataGridPopup=$("#result").children().eq(1).children().eq(1).attr("id");
        if ($.fn.yiiGridView.getChecked(DataGridPopup,"chkPopupId").length == 0){
           $('#update-dialog-message-plus').html('<?php echo t('MSG_REMIND_SELECT_ROW', 'messages', array('{0}' => 'approve')); ?>');
            $('#update-dialog-buttons-plus').html('<button type="button" id="btnOk" name="btnOk" class="button ok" onclick="$(&#039;#dialogClassroom&#039;).dialog(&#039;close&#039;)">OK</button>');
        }else{
            var ids=$.fn.yiiGridView.getChecked(DataGridPopup,'chkPopupId');
            $("#update-dialog-message-plus").html('<?php echo t('MSG_CONFIRM_APPROVE', 'messages'); ?>');
            $("#update-dialog-buttons-plus").html('<?php echo Html::hiddenField("hfId");echo Html::hiddenField("hfStatus");echo Html::buttonConfirm(t('BTN_YES'), 'statusConfirmed');echo Html::buttonConfirm(t('BTN_NO'), 'statusCanceled', 'cancel');?>');
            $("#hfId").val(ids); 
            $("#hfStatus").val("Approve");
        }
    }
    function reject(){  
        var DataGridPopup=$("#result").children().eq(1).children().eq(1).attr("id");
        if ($.fn.yiiGridView.getChecked(DataGridPopup,"chkPopupId").length == 0){
            $('#update-dialog-message-plus').html('<?php echo t('MSG_REMIND_SELECT_ROW', 'messages', array('{0}' => 'reject')); ?>');
            $('#update-dialog-buttons-plus').html('<button type="button" id="btnOk" name="btnOk" class="button ok" onclick="$(&#039;#dialogClassroom&#039;).dialog(&#039;close&#039;)">OK</button>');
        }else{
            var ids=$.fn.yiiGridView.getChecked(DataGridPopup,'chkPopupId');
            $("#update-dialog-message-plus").html('<?php echo t('MSG_CONFIRM_REJECT', 'messages'); ?>');
            $("#update-dialog-buttons-plus").html('<?php echo Html::hiddenField("hfId");echo Html::hiddenField("hfStatus");echo Html::buttonConfirm(t('BTN_YES'), 'statusConfirmed');echo Html::buttonConfirm(t('BTN_NO'), 'statusCanceled', 'cancel');?>');
            $("#hfId").val(ids); 
            $("#hfStatus").val("Reject");
        }
    } 
    
    function deleteComment(){  
        var DataGridPopup=$("#result").children().eq(1).children().eq(1).attr("id");
        if ($.fn.yiiGridView.getChecked(DataGridPopup,"chkPopupId").length == 0){
            $('#update-dialog-message-plus').html('<?php echo t('MSG_REMIND_SELECT_ROW', 'messages', array('{0}' => 'delete')); ?>');
            $('#update-dialog-buttons-plus').html('<button type="button" id="btnOk" name="btnOk" class="button ok" onclick="$(&#039;#dialogClassroom&#039;).dialog(&#039;close&#039;)">OK</button>');
        }else{
            var ids=$.fn.yiiGridView.getChecked(DataGridPopup,'chkPopupId');
            $("#update-dialog-message-plus").html('<?php echo t('MSG_CONFIRM_DELETE_COMMENT', 'messages'); ?>');
            $("#update-dialog-buttons-plus").html('<?php echo Html::hiddenField("hfId");echo Html::hiddenField("hfStatus");echo Html::buttonConfirm(t('BTN_YES'), 'statusConfirmed');echo Html::buttonConfirm(t('BTN_NO'), 'statusCanceled', 'cancel');?>');
            $("#hfId").val(ids); 
            $("#hfStatus").val("DeleteComment");
        }
    }
    //fix ie7: distance gridview - search
    $(".grid-view").css("padding","0");
</script> 
